package com.bootdo.crm.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.crm.domain.BusinessStatusDO;
import com.bootdo.crm.service.BusinessStatusService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 商机状态
 * 
 * @author cui
 * @email 1992lcg@163.com
 * @date 2020-02-20 13:14:28
 */
 
@Controller
@RequestMapping("/crm/businessStatus")
public class BusinessStatusController {
	@Autowired
	private BusinessStatusService businessStatusService;
	
	@GetMapping()
	@RequiresPermissions("crm:businessStatus:businessStatus")
	String BusinessStatus(){
	    return "crm/businessStatus/businessStatus";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("crm:businessStatus:businessStatus")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<BusinessStatusDO> businessStatusList = businessStatusService.list(query);
		int total = businessStatusService.count(query);
		PageUtils pageUtils = new PageUtils(businessStatusList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("crm:businessStatus:add")
	String add(){
	    return "crm/businessStatus/add";
	}

	@GetMapping("/edit/{statusId}")
	@RequiresPermissions("crm:businessStatus:edit")
	String edit(@PathVariable("statusId") Integer statusId,Model model){
		BusinessStatusDO businessStatus = businessStatusService.get(statusId);
		model.addAttribute("businessStatus", businessStatus);
	    return "crm/businessStatus/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("crm:businessStatus:add")
	public R save( BusinessStatusDO businessStatus){
		if(businessStatusService.save(businessStatus)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("crm:businessStatus:edit")
	public R update( BusinessStatusDO businessStatus){
		businessStatusService.update(businessStatus);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("crm:businessStatus:remove")
	public R remove( Integer statusId){
		if(businessStatusService.remove(statusId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("crm:businessStatus:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] statusIds){
		businessStatusService.batchRemove(statusIds);
		return R.ok();
	}
	
}
